package com.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

// extends WebMvcConfigurerAdapter  这是springboot1.x
// implements WebMvcConfigurer      这是springboot2.x
@Configuration
public class TomcatConfig extends WebMvcConfigurerAdapter {

    @Value("${upload.dir}")
    private  String images;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println(images);
        //在地址栏输入  http://127.0.0.1:8080/image/a.png就会到 d:/images/a.png显示
        //如果是linux还要修改
        registry.addResourceHandler("/images/**").addResourceLocations("file:"+images);
    }

}
